unit uAdd;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;

type
  TfAdd = class(TForm)
    procedure FormDestroy(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure FormClick(Sender: TObject);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  private
    { Private declarations }
    B: TBitmap;
    M: TPoint;
  public
    { Public declarations }
  end;

var
  fAdd: TfAdd;

implementation

uses uEdit, uMap, uMain;

{$R *.dfm}

procedure TfAdd.FormDestroy(Sender: TObject);
begin
  B.Free;
end;

procedure TfAdd.FormShow(Sender: TObject);
var
  X, Y: Integer;
begin
  B.Free;
  B := TBitmap.Create;
  B.LoadFromFile(Format('Sprite%d.bmp', [MapSellectID - 1]));
{  case MapSellectID of
    lrObj:
      B.LoadFromFile('Buildings.bmp');
    lrCrt:  
      B.LoadFromFile('Creatures.bmp');
  end;  }
  ClientWidth := B.Width;
  ClientHeight := B.Height;
  Left := (fMain.Width div 2) - (Width div 2);
  Top := (fMain.Height div 2) - (Height div 2);
  with B.Canvas do
  begin
    Pen.Color := clYellow;
    for Y := 0 to B.Height div 64 do
    begin
      MoveTo(0, Y * 64);
      LineTo(640, Y * 64);
    end;      
    for X := 0 to 640 do
    begin
      MoveTo(X * 64, 0);
      LineTo(X * 64, B.Height);
    end;
  end;      
end;

procedure TfAdd.FormPaint(Sender: TObject);
begin
  Canvas.Draw(0, 0, B);
end;

procedure TfAdd.FormClick(Sender: TObject);
var
  I: Word;
begin
  I := (M.Y * 10) + M.X;
  case MapSellectID of
    lrObj: MapObjectID := I;
    lrCrt: MapEnemyID := I;
  end;    
  ModalResult := mrOK;
end;

procedure TfAdd.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  M.X := X div 64;
  M.Y := Y div 64;
end;

end.
